package net.khoroshev.wschat.model.entity;

import net.khoroshev.wschat.service.auth.Authorities;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: vfirstov
 * Date: 01.12.13
 * Time: 23:01
 *
 */
public class AuthUser extends Entity implements UserDetails {

    private User authUser;
    private String firstName;
    private String lastName;


    public AuthUser(final String firstName,
                    final String lastName,
                    final String username,
                    final String password,
                    final Collection<UserAuthority> authorities ) {
        this.firstName = firstName;
        this.lastName = lastName;

        authUser = new User(username, password, authorities);
    }


    public AuthUser(final String firstName,
                    final String lastName,
                    final String username,
                    final String password,
                    final boolean enabled,
                    final Collection<UserAuthority> authorities ) {
        this.firstName = firstName;
        this.lastName = lastName;

        authUser = new User(username, password, enabled, true, true, true, authorities);
    }

    public AuthUser(final String firstName,
                    final String lastName,
                    final String username,
                    final String password) {
        this(firstName, lastName, username, password, Authorities.USER_AUTHORITIES);
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authUser.getAuthorities();
    }

    @Override
    public String getPassword() {
        return authUser.getPassword();
    }

    @Override
    public String getUsername() {
        return authUser.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return authUser.isAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return authUser.isAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return authUser.isCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return authUser.isEnabled();
    }
}
